package com.sun.controller.ums;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sun.common.MsResult;
import com.sun.pojo.UmsResource;
import com.sun.service.ums.IUmsResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 后台资源表 前端控制器
 * </p>
 *
 * @author 妙妙屋
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/resource")
public class UmsResourceController {
    @Autowired
    private IUmsResourceService umsResourceService;

    @GetMapping("/list")
    public MsResult list(Long categoryId,String nameKeyword,Long pageNum,Long pageSize,String urlKeyword){
        IPage<UmsResource> page = umsResourceService.selectPage(categoryId,nameKeyword,pageNum,pageSize,urlKeyword);
        return MsResult.isOkDataPage(page);
    }

    @PostMapping("/create")
    public MsResult crate(@RequestBody UmsResource umsResource){
        umsResource.setCreateTime(LocalDateTime.now());

        boolean ok = umsResourceService.save(umsResource);
        if(ok){
            return MsResult.isOkMessage("添加资源成功");
        }
        return MsResult.isFail("资源添加失败");
    }
}

